package com.example.chao.myphotosearch.view.activities;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.chao.myphotosearch.R;
import com.example.chao.myphotosearch.adapters.LargeDownLoadImgPagerAdapter;
import com.example.chao.myphotosearch.bean.DownloadImg;
import com.example.chao.myphotosearch.widget.ImageViewPager;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chao on 2016/4/11.
 */
public class ShowLargeDownLoadImgActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
    @Bind(R.id.down_load_large_viewPager)
    ImageViewPager downLoadLargeViewPager;
    @Bind(R.id.down_load_large_page)
    TextView downLoadLargePage;
    @Bind(R.id.down_load_large_RL)
    RelativeLayout downLoadLargeRL;
    private ArrayList<DownloadImg> downloadImgs;
    private int currentPosition;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_down_load_large_img);
        ButterKnife.bind(this);
        initData();
        downLoadLargeViewPager.setAdapter(new LargeDownLoadImgPagerAdapter(downloadImgs));
        downLoadLargeViewPager.setCurrentItem(currentPosition);
        downLoadLargeViewPager.addOnPageChangeListener(this);
    }


    public void initData() {
        currentPosition = getIntent().getIntExtra("position", 0);
        downloadImgs = (ArrayList<DownloadImg>) getIntent().getSerializableExtra("downLoadImgs");
        downLoadLargePage.setText((currentPosition + 1) + "/" + downloadImgs.size());
    }

    @OnClick(R.id.down_load_large_RL)
    public void onDownLoadLargeRLClicked(View v){
        onBackPressed();
    }

    @Override
    public void onBackPressed() {
        setResult(100, getIntent().putExtra("position", currentPosition));
        super.onBackPressed();
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        currentPosition = position;
        downLoadLargePage.setText((position + 1) + "/" + downloadImgs.size());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
